# 将股票池另存为JSON文件

import json

stock_index = [
    {'指数':{'上证指数': 'sh.000001',
            '深证成指': 'sz.399001',
            '沪深300': 'sz.000300',
            '创业板指': 'sz.399006',
            '上证50': 'sh.000016',
            '中证500': 'sh.000905',
            '中小板指': 'sz.399005',
            '上证180': 'sh.000010'},
    '股票':{'格力电器': '000651.sz',
            '平安银行': '000001.sz',
            '同花顺': '300033.sz',
            '贵州茅台': '600519.SH',
            '浙大网新': '600797.SH'}
    }
]

print(type(stock_index))

# dumps: 将数据转换成字符串

json_str = json.dumps(stock_index)

print(json_str)

print(type(json_str))


with open("stock_pool.json", 'w', encoding='utf-8') as f:
    json.dump(stock_index, f, ensure_ascii=False, indent=4)
